ReduxModelGenerator
Construct
To create a new ReduxModelGenerator
import ReduxModelGenerator , { ModelGeneratorOptions } = from '@rexlabs/model-generator';
const config: ModelGeneratorOptions = {
entities: {
api: {
createItem: (type, args) => api.post(`/${type}`, args),
fetchList: (type, args) => api.get(`/${type}`, args),
fetchItem: (type, args, id) => api.get(`/${type}/${id}`, args),
updateItem: (type, args, id) => api.patch(`/${type}/${id}`, args),
trashItem: (type, args, id) => api.delete(`/${type}/${id}`, args),
deleteItem: (type, args, id) => api.delete(`/${type}/${id}`, args),
bulkUpdateItems: (type, args) => api.put(`/${type}`, args),
bulkTrashItems: (type, args) => api.delete(`/${type}`, args),
bulkDeleteItems: (type, args) => api.delete(`/${type}`, args)
}
}
};
const modelGenerator = new ReduxModelGenerator('properties', config);
Methods
createModel(options)
Creates a new model from the ModelGenerator.
const modelGenerator = new ReduxModelGenerator('properties', config);
const model = modelGenerator.createModel();
Parameters:
| Name | Type | Description |
|---|---|---|
options | OptionObject | Provide additional options to the model or override global options |
Returns:
Type
Model
createEntityModel(options)
Creates a new entity model from the ModelGenerator.
const modelGenerator = new ReduxModelGenerator('properties', config);
const entityModel = modelGenerator.createEntityModel();
Parameters:
| Name | Type | Description |
|---|---|---|
options | OptionObject | Provide additional options to the model or override global options |
Returns:
Type
EntityModel
createValueListModel(options)
Creates a new entity model from the ModelGenerator.
const modelGenerator = new ReduxModelGenerator('tax-types', config);
const valueListModel = modelGenerator.createValueListModel();
Parameters:
| Name | Type | Description |
|---|---|---|
options | OptionObject | Provide additional options to the model or override global options |
Returns:
Type
ValueListModel